import smtplib
from email.mime.text import MIMEText
from email.header import Header

mail_host = "smtp.qq.com"  # 服务器：imap/smtp
Port_number = 465  # SSL端口：465或587或25（无协议）
mail_user = "2085195880@qq.com"  # 邮箱用户名
mail_pwd = "oozhbxrpwbsmbfed"  # 授权码
sender = "2085195880@qq.com"  # 发送者邮箱账号名
receivers = [sender, "2085195880@qq.com"]  # 接收者


def send_mail(text, subject):
    message = MIMEText(text, "plain", "utf-8")  # 文本信息
    message['From'] = sender
    message['To'] = receivers[0]
    message['Subject'] = subject

    try:
        smtpObj = smtplib.SMTP()
        smtpObj.connect(mail_host, 25)
        smtpObj.login(mail_user, mail_pwd)  # 登录
        smtpObj.sendmail(sender, receivers, message.as_string())  # 发送人，接收人，文本信息
        smtpObj.quit()
        return True
    except smtplib.SMTPException as e:
        print("Error：无法发送邮件")
        print(e)


print(send_mail(text="测试邮件", subject="主题"))
